package oo.nandian.innerclass;


public class InnerClassDemo {

    private int age = 14;
    private static String name = "a";


    public static class StaticInnerDemo {
        private static String name = "c";

        public void getName() {
            System.out.println(name);
            System.out.println(InnerClassDemo.name);
        }

        public static void getNames() {

        }
    }

    public class InnerDemo1 {
        private int age = 13;

        //        private static String name = "b";   // java8 不支持在实例内部类中存放静态属性和方法
        public void getAge() {
            System.out.println(InnerClassDemo.this.age);
            System.out.println(this.age);
            System.out.println(name);
            System.out.println(InnerClassDemo.name);
        }
    }

    public void inner() {
        int age = 11;
        class MethodInnerDemo {
            private int age = 10;

            public void getAge() {
                System.out.println(age);
                System.out.println(InnerClassDemo.this.age);
            }
        }
        MethodInnerDemo methodInnerDemo = new MethodInnerDemo();
        methodInnerDemo.getAge();
    }

    public static void staticInner() {
        int age = 9;
        class MethodStaticInnerDemo {
            private int age = 8;

            private void getAge() {
                System.out.println(age);
                System.out.println(name);
            }
        }
        MethodStaticInnerDemo methodStaticInnerDemo = new MethodStaticInnerDemo();
        methodStaticInnerDemo.getAge();
    }


    public static void main(String[] args) {

        System.out.println(" =========成员内部类=======");
        // 成员内部类  外部类实例.new 内部类()
        InnerDemo1 innerDemo1 = new InnerClassDemo().new InnerDemo1();
        innerDemo1.getAge();

        System.out.println(" =========成员静态内部类=======");
        // 静态内部类   new 外部类.内部类();
        StaticInnerDemo staticInnerDemo = new InnerClassDemo.StaticInnerDemo();
        staticInnerDemo.getName();
        StaticInnerDemo.getNames();


        System.out.println(" =========成员方法内部类=======");
        InnerClassDemo innerClassDemo = new InnerClassDemo();
        innerClassDemo.inner();


        System.out.println(" =========成员静态方法内部类=======");
        innerClassDemo.staticInner();


        System.out.println(" =========匿名内部类=======");
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("aaa");
            }
        };
        runnable.run();
    }
}
